package com.moss.cloud.common.core.constant;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 常量正则表达式
 *
 * @author 瑾年
 * @date 2023年4月16日
 */
public class Regular {
    /**
     * 邮箱正则
     */
    public static final String EMAIL_REG = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}(\\.[A-Za-z]{2,})?$";

    /**
     * url正则
     */
    public static final String URL_REG = "^(https|http|ftp|file)://[-a-zA-Z0-9+&@#/%\\?=~_|!:,\\.;]*[-a-zA-Z0-9+&@#/%=~_|\\u4e00-\\u9fa5]*$";

    /**
     * 匹配身份证
     */
    public static final String ID_CARD_REG = "^[1-9]\\d{5}(18|19|20|(3\\d))\\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";

    /**
     * 匹配由数字和字母组成的字符串
     */
    public static final String LETTER_NUMBER_REG = "^[A-Za-z0-9]+$";
    /**
     * 匹配由数字和字母特殊字符组成的字符串
     */
    public static final String LETTER_NUMBER_SPECIAL_REG = "/^(?=.*/d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&*])[/da-zA-Z~!@#$%^&*]{8,}$/";
    /**
     * 匹配中文
     */
    public static final String CHINESS = "/^[^/u4e00-/u9fa5]{1,10}$/g";

    /**
     * 整数验证规则
     */
    public static final String NUMBER_REG = "^[0-9]*[1-9][0-9]*$";
    /**
     * 图片地址
     */
    public static final String IMG_REG = "^(https|http|ftp|file)://[-a-zA-Z0-9&@#/%\\?=~_!:,\\.;\\s\\u4e00-\\u9fa5]*(jpg|jpeg|png|gif|bmp)$";

    /**
     * 校验正则表达式结果
     *
     * @param content 要校验的内容
     * @param reg     正则
     * @return 结果
     */
    public static Boolean validateInfo(String content, String reg) {
        Pattern pat = Pattern.compile(reg);
        Matcher mat = pat.matcher(content);
        return mat.matches();
    }

}
